package com.cn.zy.ehcache.utils;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

/**
 * @author zhangyi
 * @date 2018/12/13 15:35
 */
public class EhCacheUtils {

    /**
     * 设置缓存对象
     *
     * @param cacheManager
     * @param key
     * @param value
     */
    public static void setCache(CacheManager cacheManager,String key,Object value){
        Cache objectName = cacheManager.getCache("objectName");
        Element element = new Element(key,value);
        objectName.put(element);
    }

    public static Object getCache(CacheManager cacheManager,String key){
        Object object = null;
        Cache objectName = cacheManager.getCache("objectName");
        if(objectName.get(key) != null && !objectName.get(key).equals("")){
            object = objectName.get(key).getObjectValue();
        }
        return object;
    }
}
